package com.hyb.algorithm.data.struct.doublepoint;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: huyanbing
 * @Date: 2021/8/16 10:38 上午
 */
public class TwoSum {


    /**
     * 升序的数组  nums = [2,7,11,15], target = 9
     *
     * @param nums
     * @return
     */
    public List<Integer> TwoSum(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;

        List<Integer> indexList = new ArrayList<>();

        while (left <= right) {
            if (nums[left] + nums[right] == target) {
                indexList.add(left);
                indexList.add(right);
                return indexList;
            } else if (nums[left] + nums[right] > target) {
                right--;
            } else {
                left++;
            }
        }

        return indexList;

    }
}
